package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.glela.common.util.DateUtil;
import com.glela.common.util.HttpUtil;

public class 店主精选测试 {
//	public final static String url = "http://api.xzhuang.com/v2/yg_platform/";
//	public final static String url = "http://api.dev.xzhuang.com/yg_platform/";
//	public final static String url = "http://172.16.100.104:80/yg_platform/";
	public final static String url = "http://localhost:8280/";

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		upperStoreGoods();
/*        for (int i = 0; i <1000 ; i++) {

        }*/
		storeGoodsList();
//		upperStoreGoods();
//		offStoreGoods();
//		shareStore();
	}
	
	public static void shareStore() {
		JSONObject jo = new JSONObject();
		jo.put("userId", 661691);
		try {
			String post = doPost(jo.toJSONString(), url + "storeTopBanner/shareStore","application/json");
			System.out.println("shareStore========"+post);
		} catch (Exception e) {
			System.out.println("shareStore------------"+e.getMessage());
		}
	}
	
	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}
	
	/** 查询店主精选产品  */
	public static void storeGoodsList() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "60016");
		jo.put("pageNum", 1);
		jo.put("pageSize", 10);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "storeGoods/getStoreGoodsList","application/json");
			System.out.println("storeGoodsList========"+post);
		} catch (Exception e) {
			System.out.println("storeGoodsList------------"+e.getMessage());
		}
	}
	
	/** 上架店主精选产品  */
	public static void upperStoreGoods() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "60016");
		jo.put("goodsId", 1755);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "storeGoods/upperStoreGoods","application/json");
			System.out.println("upperStoreGoods========"+post);
		} catch (Exception e) {
			System.out.println("upperStoreGoods------------"+e.getMessage());
		}
	}
	/** 下架店主精选产品  */
	public static void offStoreGoods() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "258");
		jo.put("goodsId", 1755);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "storeGoods/offStoreGoods","application/json");
			System.out.println("offStoreGoods========"+post);
		} catch (Exception e) {
			System.out.println("offStoreGoods----------"+e.getMessage());
		}
	}
}
